#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll quickpow(ll a,ll b, ll mod){
    ll ans = 1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans%mod;
}

int main() {
  int t;
  ll n;
  cin>>t;
  while(t--){
    cin>>n;
    ll a = n%10;
    if(n%2==0||n%5==0) {
      if (n%2) cout<<quickpow(a,5,10)<<endl;
      else cout<<quickpow(a,4,10)<<endl;
    } else {
      cout<<quickpow(a,1,10)<<endl;
    }
  }
}